package com.cbtx.module.base;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

/**
 * author : joker.peng
 * e-mail : joker@fiture.com
 * date   : 2021/6/10 6:14 PM
 * desc   :
 */
public class SpUtils {

    /**
     * 亮度
     */
    public static final String BRIGHTNESS = "BRIGHTNESS";

    /**
     * token
     */
    public static final String TOKEN_KEY = "mips_token";

    /**
     * 本地最新节目批次号
     */
    public static final String NEW_PROGRAM_UPDATE_TIME = "new_program_update_time";

    /**
     * 店铺信息
     */
    public static final String STORE_INFO = "store_info";

    /**
     * 酒店文案
     */
    public static final String STORE_TEXT = "store_text";
    /**
     * 本地最新设置批次号
     */
    public static final String NEW_SETTING_UPDATE_TIME = "new_setting_update_time";

    /**
     * 本地最新升级批次号
     */
    public static final String NEW_UPGRADE_UPDATE_TIME = "new_upgrade_update_time";
    /**
     * 过期时间
     */
    public static final String EXPIRES_TIME = "expires_time";

    /**
     * 服务器ip
     */
    public static final String SERVER_IP = "SERVER_IP";

    /**
     * 服务器端口号
     */
    public static final String SERVER_PORT = "SERVER_PORT";

    /**
     * 开机时间
     */
    public static final String BOOT_TIME = "BOOT_TIME";
    /**
     * 关机时间
     */
    public static final String SHUTDOWN_TIME = "SHUTDOWN_TIME";

    public static final String OSS_BUCKETNAME = "OSS_BUCKETNAME";
    public static final String OSS_ENDPOINT = "OSS_ENDPOINT";

    /**
     * 添加string
     */
    public static void putString(String key, String value) {
        SharedPreferences.Editor edit = PreferenceManager.
                getDefaultSharedPreferences(ContextManager.INSTANCE.getContext()).edit();
        edit.putString(key, value);
        edit.apply();
    }


    public static void putInt(String key, int value) {
        SharedPreferences.Editor edit = PreferenceManager.
                getDefaultSharedPreferences(ContextManager.INSTANCE.getContext()).edit();
        edit.putInt(key, value);
        edit.apply();
    }

    public static void putLong(String key, long value) {
        SharedPreferences.Editor edit = PreferenceManager.
                getDefaultSharedPreferences(ContextManager.INSTANCE.getContext()).edit();
        edit.putLong(key, value);
        edit.apply();
    }

    /**
     * 获取sp里面的string值
     *
     * @param key 需要获取的key
     * @return 结果
     */
    public static String getString(String key) {
        SharedPreferences pref = PreferenceManager
                .getDefaultSharedPreferences(ContextManager.INSTANCE.getContext());
        return pref.getString(key, "");
    }


    public static int getInt(String key, int def) {
        SharedPreferences pref = PreferenceManager
                .getDefaultSharedPreferences(ContextManager.INSTANCE.getContext());
        return pref.getInt(key, def);
    }

    public static long getLong(String key) {
        SharedPreferences pref = PreferenceManager
                .getDefaultSharedPreferences(ContextManager.INSTANCE.getContext());
        return pref.getLong(key, -1L);
    }

    public static void remove(String key) {
        SharedPreferences pref = PreferenceManager
                .getDefaultSharedPreferences(ContextManager.INSTANCE.getContext());
        pref.edit().remove(key).apply();
    }
}
